package com.riven.bilibilidemo.bean;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.riven.bilibilidemo.R;

/**
 * Created by qwert on 2017/3/10.
 */

public class PartitionRecyclerViewAdapter extends RecyclerView.Adapter<PartitionRecyclerViewAdapter.ViewHolder>{
    private final Context context;
    private String[] itemNames = new String[] {
            "直播", "番剧", "动画",
            "音乐", "舞蹈", "游戏",
            "科技", "生活", "鬼畜",
            "时尚", "广告", "娱乐",
            "电影", "电视剧", "游戏中心",
    };

    private int[] itemIcons = new int[] {
            R.drawable.ic_category_live, R.drawable.ic_category_t13,
            R.drawable.ic_category_t1, R.drawable.ic_category_t3,
            R.drawable.ic_category_t129, R.drawable.ic_category_t4,
            R.drawable.ic_category_t36, R.drawable.ic_category_t160,
            R.drawable.ic_category_t119, R.drawable.ic_category_t155,
            R.drawable.ic_category_t165, R.drawable.ic_category_t5,
            R.drawable.ic_category_t23, R.drawable.ic_category_t11,
            R.drawable.ic_category_game_center
    };
    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public PartitionRecyclerViewAdapter(Context context){
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_home_region, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.mItemIcon.setImageResource(itemIcons[position]);
        holder.mItemText.setText(itemNames[position]);
    }

    @Override
    public int getItemCount() {
        return itemIcons.length;
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        ImageView mItemIcon;

        TextView mItemText;
        public ViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(onItemClickListener!=null){
                        onItemClickListener.ItemClickListener(getPosition());
                    }
                }
            });
            mItemIcon = (ImageView) itemView.findViewById(R.id.item_icon);
            mItemText = (TextView) itemView.findViewById(R.id.item_title);
        }
    }
    public interface OnItemClickListener{
        void ItemClickListener(int position);
    }
}
